package cn.itcast.shopping;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ListCarServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();


		//	  List  list = (List) request.getSession(false).getAttribute("list");
		HttpSession session = request.getSession();

		if (session==null) {
			out.print("你没有购买任何商品");
			return ;
		}
		List<Book> list=	(List) session.getAttribute("list");
		out.write("你购买了如下商品");
		for (Book book : list) {
			out.write(book.getName());
		}





	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
		response.setContentType("text/html;charset=UTF-8");

	}

}
